package com.company.class2;

/**
 * @Classname demo5
 * @Description 位运算
 * @Date 2022/4/10 20:08
 * @Created by zbw
 */

public class demo5 {
    public static void main(String[] args) {
        byte a = 74, b = 45;

        //计算出来的结果，从10进制看，看不出东西
        int c = a & b;
        System.out.println(c);
        System.out.println(a&b);

        int d = a | b;
        System.out.println(d);
        int e = ~a;
        System.out.println(e);

        //位运算的与或也可以用来进行布尔数的判断
        boolean ba = true;
        boolean bb = false;
        System.out.println(ba&bb);
        System.out.println(ba|bb);
        //非是不能用与boolean数的
//        System.out.println(~ba);

        //异或
        int xor = a^b;
        System.out.println(xor);

        int axor = xor^a;
        int bxor = xor^b;
        System.out.println("a和结果异或应该得到b "+axor);
        System.out.println("b和结果异或应该得到a "+bxor);

//        int bleft1 = b << 2;
//        System.out.println(bleft1);
        byte bleft1 = (byte)( b << 2);
        System.out.println(bleft1);



    }
}
